<?php
namespace Home\Controller;
use Think\Controller;
/**
 * Created by PhpStorm.
 * User: 97628
 * Date: 2016/6/18
 * Time: 21:17
 */
function isPC(){
    $userAgent = $_SERVER['HTTP_USER_AGENT'];
    $Agents = array(
        "Android",
        "iPhone",
        "SymbianOS",
        "Windows Phone",
        "iPad",
        "iPod"
    );
    $isPC = true;
    foreach($Agents as $key=>$value){
        if(stripos($userAgent, $value) != false){
            $isPC = false;
        }
    }
    //return false;
    return $isPC;
}
/**
 * 移动端模版渲染
 * @param $content string
 * @return mixed 渲染后的结果string
 */
function render($content){
    if(isPC()){
        $content = str_ireplace( '<script></script>',
            '<script src="__JS__/mainP.js" type="text/javascript" charset="utf-8"></script>',
            $content);
    }else{
        $content = str_ireplace( '<head>',
            '<head><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">',
            $content);
        $content = str_ireplace( '<script></script>',
            '<script src="__JS__/mainM.js" type="text/javascript" charset="utf-8"></script>',
            $content);
    }
    return $content;
}

?>